package com.easy.neo4j.repository;

import com.easy.neo4j.entry.dt.Subway;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: CoolPro
 * @Desc:
 * @create: 2024-03-18 18:39
 **/
@Repository
public interface SubwayRepository extends Neo4jRepository<Subway, Long> {
    @Query("MATCH (n1:Subway) " +
            "WITH  n1,point({latitude: toFloat(n1.lng), longitude: toFloat(n1.lat)}) AS sitePoint, " +
            "     point({latitude: toFloat($lat), longitude: toFloat($lng)}) AS inputPoint " +
            "WITH n1, point.distance(sitePoint,inputPoint) as Distance " +
            "WHERE Distance < 1000 " +
            "return n1")
    List<Subway> findALlSubway(@Param("lat")String lat,@Param("lng")String lng);

    @Query("MATCH p=()-[:SubwayLine {lineName:$lineName}]->() return p")
    List<Subway> findSubwayByLineName(@Param("lineName") String lineName);
}
